package com.example.wanghao.wangyixinwen.act;

import android.os.Bundle;
import android.support.v4.app.Fragment;

import com.example.wanghao.wangyixinwen.R;
import com.example.wanghao.wangyixinwen.fragment.HomeFragment;
import com.example.wanghao.wangyixinwen.fragment.MenuFragment2;
import com.jeremyfeinstein.slidingmenu.lib.SlidingMenu;
import com.jeremyfeinstein.slidingmenu.lib.app.SlidingFragmentActivity;

public class MainActivity extends SlidingFragmentActivity {

    private SlidingMenu mSm;
    private MenuFragment2 mMenuFragment;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //设置主界面的布局
        setContentView(R.layout.activity_main);
        //LogTools.LogInfo(MainActivity.this,"账号:123, 密码:321");
        //设置菜单界面布局
        setBehindContentView(R.layout.activity_menu);
        //获取侧滑菜单对象
        mSm = getSlidingMenu();
        /**
         * SlidingMenu.LEFT:侧滑菜单显示在左边
         * SlidingMenu.RIGHT:侧滑菜单显示在右边
         * SlidingMenu.LEFT_RIGHT:侧滑菜单显示在左右
        */
        mSm.setMode(SlidingMenu.LEFT);
        /*
        　* 设置注译模板
          * SlidingMenu.TOUCHMODE_NONE : 禁止触摸模式
          * SlidingMenu.TOUCHMODE_FULLSCREEN全屏模式
          * lidingMenu.TOUCHMODE_MARGIN:边缘模式
        */
        mSm.setTouchModeAbove(SlidingMenu.TOUCHMODE_MARGIN);
        //设置菜单界面显示后,主界面剩余显示的宽度
        mSm.setBehindOffsetRes(R.dimen.slidingmenu_width);
        //设置菜单界面与主界面的阴影
        mSm.setShadowDrawable(R.drawable.shadow);
        //设置阴影的宽度
        mSm.setShadowWidthRes(R.dimen.shadow_width);
        //如果设置左右必须要设置第二个界面
       /* mSm.setSecondaryMenu(R.layout.activity_menu);
        mSm.setSecondaryShadowDrawable(R.drawable.shadow);
*/

        //实现菜单,fragment替换
        /*MenuFragment menuFragment = new MenuFragment();
        getSupportFragmentManager().beginTransaction().replace(R.id.fl_menu,menuFragment).commit();*/
        mMenuFragment = new MenuFragment2();
        getSupportFragmentManager().beginTransaction().replace(R.id.fl_menu, mMenuFragment).commit();

        //设置主界面的默认界面
       // Fragment1 fragment1 = new Fragment1();
        HomeFragment homeFragment = new HomeFragment();
        getSupportFragmentManager().beginTransaction().replace(R.id.fl_main,homeFragment,"HOME").commit();
    }

    //菜单界面控制主界面进行切换工作
    public void swithFragment(Fragment fragment) {
        getSupportFragmentManager().beginTransaction().replace(R.id.fl_main,fragment).commit();
        //让菜单界面隐藏
        mSm.toggle();//判断当前的界面菜单的状态进行显示或者隐藏
    }

    public MenuFragment2 getMenuFragment(){
        return mMenuFragment;
    }
    public HomeFragment getHomeFragment(){
        HomeFragment homeFragment = (HomeFragment) getSupportFragmentManager().findFragmentByTag("HOME");

        return homeFragment;
    }


}
